function get_filter_value()
{
    var result = {};
    var rating = [];
    var service = [];
    $('#accommodation_filter input:checkbox:checked[name="rating"]').each(function()
    {
        if (!$(this).parent().hasClass("disabled"))
        {
            rating.push($(this).val());
        }
    });
    $('#accommodation_filter input:checkbox:checked[name="service"]').each(function()
    {
        service.push($(this).val());
    });
    //var service = $('input:checkbox:checked[name="service"]').reduce(function(previousValue, currentValue, index, array) { return previousValue+currentValue; },0).get();
    service = service.reduce(function(previousValue, currentValue, index, array) { return parseInt(previousValue)+parseInt(currentValue); },0);
    if (service > 0)
    {
        result.service_fil = service;
    }
    if (rating.length > 0 )
    {
        result.rating_fil = rating;
    }
    return result;
}

jQuery(document).ready
(function(e)
{
    if (typeof  RELOAD_FUNC[1] == "undefined")
    {
        RELOAD_FUNC[1] = [];
    }
   //Refresh status of filter option
   RELOAD_FUNC[1][1] = function(data,container)
   {
    var filter_count = data.Records[0][0];
    //Refresh rating first
    var updated = false;//Flag for indicate filter has re enabled or not .
    var rating_filter = $(container).find("#rating_filter");
    var rating_count = 0;
    var rating_has_click = false;
    rating_filter.find(".btn,.btn-link").each(function(index)
    {
        var rating = parseInt(index + 1);
        
        //$(this).find(".text span").last().text("("+filter_count[3][rating - 1]+")");
        if (filter_count[3][rating - 1] == 0)
        {
            $(this).addClass("disabled");
        }
        else
        {
            
            if ($(this).hasClass("disabled") && $(this).hasClass("active"))
            {
                updated = true;
                
            }
            if ($(this).hasClass("active") && !$(this).hasClass("disabled"))
            {
                rating_has_click = true;
                rating_count+=parseInt(filter_count[3][rating - 1]);
            }
            $(this).removeClass("disabled");
        }
    });
    if (rating_has_click)
    {
        $(container).find(".rate_count").html("("+rating_count+")");
    }
    else
    {
        $(container).find(".rate_count").html("");
    }
    //Refresh service 
    var service_filter = $(container).find("#service_filter");
    var service_count=0;
    var service_has_click = false;
    service_filter.find(".btn,.btn-link").each(function(index)
    {
        var e_count = filter_count[4][""+Math.pow(2,8-index)];
        
        if (e_count == 0)
        {
            $(this).addClass("disabled");
        }
        else
        {
            $(this).removeClass("disabled");
        }
        if ($(this).hasClass("active") && !$(this).hasClass("disabled"))
        {
            service_count+=parseInt(e_count);
            service_has_click=true;
        }
        
    })
    if (service_has_click)
    {
        $(container).find(".service_count").html("("+service_count+")");
    }
    else
    {
        $(container).find(".service_count").html("");
    }
    if (updated)
    {
        on_switch_page();
        return true;
    }
   };
FILTER_FUNC[1] = get_filter_value;
jQuery("#filter_reset").click(function(e){
    e.preventDefault();
    $('#accommodation_filter input:checkbox:checked[name="rating"]').each(function()
    {
        $(this).attr("checked",false);
        $(this).parent().removeClass("active");
    });
    $('#accommodation_filter input:checkbox:checked[name="service"]').each(function()
    {
       $(this).attr("checked",false);
       $(this).parent().removeClass("active");
    });
    on_switch_page();
    
    }
    
    );
jQuery("#accommodation_filter").change(on_switch_page)
    jQuery('#accommodation_filter input:checkbox[name="service"]').each(function()
    {
       jQuery(this).parent().tooltip();
    });
});